class PopBox{
	constructor(box) {
	    this.oBox = box;
		this.oCloseBtn = null;
	}
	
	setPosition(){
		//凡是和offset有关的属性，使用时，元素必须在页面显示
		this.oBox.style.display = "block";
		this.oBox.style.left = innerWidth/2 - this.oBox.offsetWidth/2 + "px";
		this.oBox.style.top = innerHeight/2 - this.oBox.offsetHeight/2 + "px";
		this.createCloseBtn();
		this.closeBox();
	}
	
	createCloseBtn(){
		if(this.oCloseBtn == null){
			this.oCloseBtn = document.createElement("button");
			//注意提前追加，否则offset相关属性无法获取
			this.oBox.appendChild(this.oCloseBtn);
			this.oCloseBtn.style.width = "50px";
			this.oCloseBtn.style.height = "25px";
			this.oCloseBtn.style.position = "absolute";
			this.oCloseBtn.style.left = this.oBox.offsetWidth - this.oCloseBtn.offsetWidth + "px";
			this.oCloseBtn.innerHTML = "X";
		}
	}
	
	closeBox(){
		let that = this;
		this.oCloseBtn.onclick = function(){
			that.oBox.style.display = "none";
		}
	}
}